package api

import (
	"api/model/mysql"
	"api/routerquest"
	"github.com/gin-gonic/gin"
	"net/http"
)

func CreateGood(c *gin.Context) {
	var App routerquest.Goods
	if err := c.ShouldBindJSON(&App); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	stu := mysql.Goods{
		GoodsId:    App.GoodsId,
		GoodsName:  App.GoodsName,
		GoodsPrice: App.GoodsPrice,
		GoodsNum:   App.GoodsNum,
	}
	err := stu.CreateGoods()
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	c.JSON(http.StatusOK, gin.H{"code": "200", "msg": "添加成功", "data": stu})
}
